package co.yixiang.retail.biz.order.controller;

import co.yixiang.common.core.api.ApiResult;
import co.yixiang.common.log.annotation.Log;
import co.yixiang.common.security.utils.SecurityUtils;
import co.yixiang.retail.biz.order.service.YxStoreOrderService;
import co.yixiang.retail.common.domain.YxStoreOrder;
import co.yixiang.retail.common.dto.YxStoreOrderSalesDetailQueryCriteria;
import co.yixiang.retail.common.dto.YxStoreOrderSalesQueryCriteria;
import co.yixiang.retail.common.dto.YxStoreOrderShipmentsDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单")
@RestController
@RequestMapping("/order")
public class YxStoreOrderController {
    @Autowired
    private YxStoreOrderService yxStoreOrderService;

    @Log("确认支付")
    @ApiOperation("确认支付")
    @PostMapping(value = "/sumitOrder")
    public  ResponseEntity<Object> sumitOrder(@Validated @RequestBody YxStoreOrder yxStoreOrder) {
        yxStoreOrderService.sumitOrder(yxStoreOrder);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation(value = "查询销货订单")
    @GetMapping(value = "/yxStoreOrders")
    public ResponseEntity getSalesYxStoreOrders(YxStoreOrderSalesQueryCriteria criteria,
                                                Pageable pageable) {
        return new ResponseEntity<>(yxStoreOrderService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @ApiOperation(value = "查询订单详情")
    @GetMapping(value = "/yxStoreOrders/detail")
    public ResponseEntity getSalesYxStoreOrdersDetail(YxStoreOrderSalesDetailQueryCriteria criteria) {
        return new ResponseEntity<>(yxStoreOrderService.queryAll(criteria), HttpStatus.OK);
    }

    @ApiOperation(value="销货订单发货")
    @PostMapping(value = "/yxStoreOrder/shipments")
    public ApiResult<Boolean> deliveryOrder(YxStoreOrderShipmentsDto cmd ){
        yxStoreOrderService.shipments(cmd);
        return ApiResult.ok();
    }

    @ApiOperation(value="销货订单拒单")
    @PostMapping(value = "/yxStoreOrder/refuse/bill")
    public ApiResult<Boolean> refuseBill(YxStoreOrderShipmentsDto cmd ){
        yxStoreOrderService.refuseBill(cmd);
        return ApiResult.ok();
    }
}
